package cn.wolfcode.wolf2w.rediskey;

import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;

@Getter
public enum  RedisKeys {
    // 验证码的重构 key
    VERIFY_CODE("Verify_Code", Consts.VERIFY_CODE_VAI_TIME*60L),
    // 令牌的重构 key
    TOKEN("token",Consts.USER_INFO_TOKEN_VAI_TIME*60L),
    // 控制频率的重构 key
    FREQUENCY("frequency",Consts.VERIFY_CODE_VAI_TIME*60L);
    private String prefix;
    private Long time;
    // 设计 redis key 前缀为 prefix,有效时间为 time
    private RedisKeys(String prefix,Long time){
        this.prefix = prefix;
        this.time = time;
    }

    // 拼接 redis 中的 key
    public String getRedisKey(String... values){
        StringBuilder stringBuilder = new StringBuilder();
        // 返回拼接后能见名知意的 redis key
        StringBuilder redisKey = stringBuilder.append(prefix).append(":");
        for (String value : values) {
            redisKey.append(value);
        }
        return redisKey.toString();
    }

}
